package noobteam.deartrainer.controller;

import noobteam.deartrainer.service.CourseInfoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 高乾威
 */
@RestController
public class CourseInfoController {
    @Resource
    private CourseInfoService courseInfoService;

    @RequestMapping("/addCourse")
    public String addCourse(@RequestParam Map<String,String> map){
        String msg="添加失败";
        boolean flag=courseInfoService.trainerAddCourse(map);
        if(flag){
            msg="添加成功";
        }
        return msg;
    }

    @RequestMapping("/getAllCourseCodeInfo")
    public List<Map<String,Object>> findAllCourseCodeInfo(){
        return courseInfoService.getAllCourseCodeInfo();
    }

    @RequestMapping("/getAllCourseInfo")
    public List<Map<String,Object>> findAllCourseInfo(){
        return courseInfoService.getAllCourseInfo();
    }

    @RequestMapping("/getCourseInfoById")
    public Map<String,Object> getCourseInfoById(@RequestParam int courseId){
        return courseInfoService.getCourseInfoById(courseId);
    }

    @RequestMapping("/getCourseListByTrainerPhone")
    List<Map<String, Object>> getCourseInfoByTrainerPhone(@RequestParam int trainerPhone){
        return courseInfoService.getCourseListByTrainerPhone(trainerPhone);
    }

    @RequestMapping("/getCourseListOrderByDate")
    public List<Map<String, Object>> getCourseListOrderByDate(){
        return courseInfoService.getCourseListByDate();
    }

    @RequestMapping("/getCourseListOrderByName")
    public List<Map<String, Object>> getCourseListOrderByName() {
        return courseInfoService.getCourseListOrderByName();
    }

    @RequestMapping("/getCourseListOrderByHot")
    public List<Map<String, Object>> getCourseListOrderByHot() {
        return courseInfoService.getCourseListOrderByNum();
    }

    @RequestMapping("/getCourseListByType")
    public List<Map<String, Object>> getCourseListByType(@RequestParam String courseType) {
        return courseInfoService.getCourseListOrderByType(courseType);
    }

    @RequestMapping("/updateCourseMsg")
    public boolean updateCourseMsg(@RequestParam Map<String, String> course) {
        return courseInfoService.updateCourseMsg(course);
    }

    @RequestMapping("/getTrainerCourseOrderByStudentNum")
    public List<Map<String, Object>> getTrainerCourseOrderByStudentNum(@RequestParam Integer trainerId) {
        return courseInfoService.getTrainerCourseOrderByStudentNum(trainerId);
    }

    @RequestMapping("/getTrainerCourseOrderByStartTime")
    public List<Map<String, Object>> getTrainerCourseOrderByStartTime(@RequestParam Integer trainerId) {
        return courseInfoService.getTrainerCourseOrderByStartTime(trainerId);
    }

    @RequestMapping("/updateCoursePhoto")
    public String updatePhoto(@RequestParam Map<String,String> map ){
        String msg="修改失败";
        boolean flag = courseInfoService.updateCoursePhoto(map);
        if(flag){
            msg="修改成功";
        }
        return msg;
    }

    @RequestMapping("/deleteCourseById")
    public boolean deleteCourseById(@RequestParam int courseId){
        boolean b = courseInfoService.deleteCourseById(courseId);
        return b;
    }
}
